package com.twu.biblioteca;

public class MenuController {

    private final BibliotecaApp app;

    private ReserveController reserveController;

    public MenuController(BibliotecaApp app) {
        this.app = app;
    }

    public void setReserveController(ReserveController reserveController) {
        this.reserveController = reserveController;
    }

    public void enter() {
        app.getUserInterface().showMenu();
        String menuOption = app.getUserInterface().nextInput();
        while (menuOption == null || menuOption.equals("quit") == false) {
            select(menuOption);
            menuOption = app.getUserInterface().nextInput();
        }
    }

    public void select(String menuOption) {
        if ("list".equals(menuOption)) {
            app.getUserInterface().showBookList(app.getBookShelf().getBooks());
        } else if ("membership".equals(menuOption)) {
            app.getUserInterface().showMembershipInfo();
        } else if ("reserve".equals(menuOption)) {
            reserveController.enter();
        } else {
            app.getUserInterface().showInvalidCommandMessage(menuOption);
        }
    }

}
